#include "Server.h"
#include "Object.h"

#include <iostream>

using boost::asio::ip::udp;

int main( int argc, char** argv)
{

	try 
	{
		Server _server;
 		int frame = 0;
		int dt = 0.03f;
		
		while(true)
		{
			Object::receiveMessage();
			std::map<udp::endpoint, Player>::iterator playerIt;
			_server.updatePhysics( dt );
			for (playerIt = _server._playerMap.begin(); playerIt != _server._playerMap.end(); playerIt++) {
				
				playerIt->second.update();
				//####################################
				//Testdata Client:
				//std::cout << playerIt->second._object->attitude << std::endl;
				//playerIt->second._object->attitude += 0.01;
				//playerIt->second._object->fX = 0.0;
				//playerIt->second._object->fY = 1.0;
				//playerIt->second._object->fZ = 0.0;
				//####################################
				Object::sendMessage(playerIt->second._object);
			}

/*
			boost::posix_time::milliseconds waitTime(500);
			boost::this_thread::sleep(waitTime);
			printf("%s%d\n", "frame: ", frame++);
*/

		}
	} 
	catch (std::exception& e) 
	{
		std::cerr << e.what() << std::endl;
	}
	
	return 0;
}
